<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!doctype html>
<html>
<head>
    <%@ include file="/common.jsp" %>
    <title>入驻申请 公司信息</title>
    <script type="text/javascript" src="${ctx }/statics/libs/vue.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx }/css/weui.min.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/aui/css/aui.css"/>
</head>
<body>
<section class="aui-content">
    <img src="${ctx}/statics/aui/images/regLogo.png" style="width: 100%;">
</section>

<div class="page">
    <div class="page__bd" style="height: 100%;">
        <div class="weui-tab">
            <div class="weui-navbar">
                <div class="weui-navbar__item weui-bar__item_on" id="isApplyDiv1">
                    第一步
                </div>
                <div class="weui-navbar__item" id="isApplyDiv2">
                    第二步
                </div>
                <div class="weui-navbar__item" id="isApplyDiv3">
                    第三步
                </div>
            </div>
            <div class="weui-tab__panel">

                <form action="${ctx}/auth/submitCompany" method="post" id="submitCompany" enctype="multipart/form-data">

                    <div class="page__bd isApplyDiv" id="isApply1">
                        <input type="hidden" id="applyStart" name="applyStart" value="${applyStart}">
                        <div class="weui-cells__title"><h4 class="page__title">企业信息（请输入真实的企业/公司信息）</h4></div>
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell" id="s_nameDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">企业名称</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="s_name" name="s_name" maxlength="18" value="${merchantInfo.shopName}"
                                           type="text"
                                           placeholder="您的企业名称">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                            <div class="weui-cell" id="shopAbbreviationDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">企业简称</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="shopAbbreviation" name="shopAbbreviation" value="${merchantInfo.shopAbbreviation}"
                                           maxlength="10"
                                           type="text" placeholder="您的企业简称">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                            <div class="weui-cell" id="s_addrDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">企业地址</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="s_addr" name="s_addr" maxlength="50" value="${merchantInfo.shopAddress}"
                                           type="text"
                                           placeholder="您的企业地址">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                            <div class="weui-cell" id="telephoneDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">客服电话</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="telephone" name="telephone" maxlength="15" value="${merchantInfo.telephone}"
                                           type="text" placeholder="您的客服电话">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                        </div>
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell" id="usernameDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">联系人姓名</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="username" name="username" maxlength="10"  value="${merchantInfo.username}"
                                           type="text" placeholder="您的姓名">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                            <div class="weui-cell" id="mobileDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">联系人电话</label></div>
                                <div class="weui-cell__bd">
                                    <input type="hidden" id="oldMobile" name="oldMobile" value="${merchantInfo.mobilephone}">
                                    <input class="weui-input" id="mobile" name="mobile"  maxlength="11" value="${merchantInfo.mobilephone}"
                                           type="text" placeholder="您的联系电话" onkeyup="repNumber(this)" >
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                            <div class="weui-cell" id="emailDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">联系人邮箱</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="email" name="email" maxlength="25" value="${merchantInfo.email}"
                                           type="text" placeholder="您的联系邮箱">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                        </div>
                        <section class="aui-content" style="margin-top: 14px; padding-left: 20px; padding-right: 20px;">
                            <p>
                                <input type="button" id="subButtonCompany" class="aui-btn aui-btn-info aui-btn-block"
                                       onclick="onclkAppCompany();"
                                       value="下一步">
                            </p>
                            <br/>
                            <br/>
                        </section>
                    </div>

                </form>

            </div>
        </div>
    </div>
</div>

<div id="dialogs">
    <div class="js_dialog" id="iosDialog2" style="display: none;">
        <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__bd" id="DialogMessage"></div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary DeleteDefault">确定</a>
            </div>
        </div>
    </div>

    <!-- loading toast -->
    <div id="loadingToast" style="display:none;">
        <div class="weui-mask_transparent"></div>
        <div class="weui-toast">
            <i class="weui-loading weui-icon_toast"></i>
            <p class="weui-toast__content">数据处理中</p>
        </div>
    </div>
</div>

<script type="text/javascript">
    //弹框提示初始化
    var $iosDialog2 = $('#iosDialog2');
    $('#dialogs').on('click', '.DeleteDefault', function () { //取消按钮事件
        $(this).parents('.js_dialog').fadeOut(200);
    });

    /**
     * 只能输入数字  手机号
     * @param obj
     * @returns
     */
    function repNumber(obj) {
        var reg = /^[\d]+$/g;
        if (!reg.test(obj.value)) {
            var txt = obj.value;
            txt.replace(/[^0-9]+/, function (char, index, val) { //匹配第一次非数字字符
                obj.value = val.replace(/\D/g, "");//将非数字字符替换成""
                var rtextRange = null;
                if (obj.setSelectionRange) {
                    obj.setSelectionRange(index, index);
                } else { //支持ie
                    rtextRange = obj.createTextRange();
                    rtextRange.moveStart('character', index);
                    rtextRange.collapse(true);
                    rtextRange.select();
                }
            })
        }
    }
    /*/!**
     * 只能输入数字  手机号
     * @param obj
     * @returns
     *!/
    function repTelephone(obj) {
        /!*var reg = /^0\d{2,3}-\d{7,8}(-\d{1,6})?$/;
        if (!reg.test(obj.value)) {*!/
            var txt = obj.value;
            txt.replace(/^[\d\-]+$/, function (char, index, val) { //匹配第一次非数字字符
                obj.value = val.replace(/\D/g, "");//将非数字字符替换成""
                $("#DialogMessage").html(val+"==="+obj.value);
                $iosDialog2.fadeIn(200);
                var rtextRange = null;
                if (obj.setSelectionRange) {
                    obj.setSelectionRange(index, index);
                } else { //支持ie
                    rtextRange = obj.createTextRange();
                    rtextRange.moveStart('character', index);
                    rtextRange.collapse(true);
                    rtextRange.select();
                }
            })
    }*/

    /**
     * 查询手机号是否入驻过  是否为收款员
     */
    function checkMobile(mobile) {
        if (!(/^1[34578]\d{9}$/.test(mobile.trim()))) {
            $("#DialogMessage").html("请输入正确的手机号");
            $iosDialog2.fadeIn(200);
            $('#mobileDiv').addClass("weui-cell_warn");
            $('#subButtonCompany').attr('disabled', true);
            $('#subButtonCompany').removeClass("aui-btn-info");
            $('#subButtonCompany').addClass("weui-btn_primary_dsab");
        } else {
            var oldMobile=$("#oldMobile").val();
            var applyStart=$("#applyStart").val();
            if(applyStart=="merInfoOne"&&oldMobile==mobile) {
                $('#mobileDiv').removeClass("weui-cell_warn");
                $('#subButtonCompany').removeAttr("disabled");
                $('#subButtonCompany').removeClass("weui-btn_primary_dsab");
                $('#subButtonCompany').addClass("aui-btn-info");
            }else{
                $.ajax({
                    type: "POST",
                    url: "${ctx}/auth/checkMobile",
                    data: {mobile: mobile},
                    success: function (r) {
                        var result = JSON.parse(r);
                        if (result.code == '500') {
                            $("#DialogMessage").html(result.msg);
                            $iosDialog2.fadeIn(200);
                            $('#mobileDiv').addClass("weui-cell_warn");

                            $('#subButtonCompany').attr('disabled', true);
                            $('#subButtonCompany').removeClass("aui-btn-info");
                            $('#subButtonCompany').addClass("weui-btn_primary_dsab");
                        } else if (result.code == '0') {
                            $('#mobileDiv').removeClass("weui-cell_warn");

                            $('#subButtonCompany').removeAttr("disabled");
                            $('#subButtonCompany').removeClass("weui-btn_primary_dsab");
                            $('#subButtonCompany').addClass("aui-btn-info");
                        }
                    }
                });
            }
        }
    }

    //光标离开事件
    $(".weui-input").blur(function(){
        var divname=this.name+"Div";
        if ($(this).val().trim().length == 0) {
            $('#'+divname).addClass("weui-cell_warn");
        }else{
            $('#'+divname).removeClass("weui-cell_warn");
        }
        if(divname=="mobileDiv" && $(this).val().length==11){  //手机验证
            checkMobile($(this).val());
        }else if(divname=="mobileDiv" && $(this).val().length != 11){
        	$('#'+divname).addClass("weui-cell_warn");
        }
        if(divname=="telephoneDiv" && !(/^0\d{2,3}-?\d{7,8}$/.test($(this).val())) ){  //客服电话验证
        	$('#'+divname).addClass("weui-cell_warn");
        }
        if(divname=="emailDiv" && !(/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test($(this).val())) ){  //邮箱验证
        	$('#'+divname).addClass("weui-cell_warn");
        }
        
        
    });
    ///商户入驻 数据验证
    function valdateAppCompany(objName) {
        $('#s_nameDiv').removeClass("weui-cell_warn");
        $('#shopAbbreviationDiv').removeClass("weui-cell_warn");
        $('#s_addrDiv').removeClass("weui-cell_warn");
        $('#telephoneDiv').removeClass("weui-cell_warn");
        $('#usernameDiv').removeClass("weui-cell_warn");
        $('#emailDiv').removeClass("weui-cell_warn");
        $('#mobileDiv').removeClass("weui-cell_warn");
        var s_name = $("#s_name").val();
        var shopAbbreviation = $("#shopAbbreviation").val();
        var s_addr = $("#s_addr").val();
        var telephone = $("#telephone").val();
        var username = $("#username").val();
        var mobile = $("#mobile").val();
        var email = $("#email").val();
        var errorMessage = "";
        if ((objName=="s_name"||objName=="objName")&&s_name.trim().length == 0) {
            errorMessage = "请填写企业名称";
            $('#s_nameDiv').addClass("weui-cell_warn");
        } if ((objName=="shopAbbreviation"||objName=="objName")&&shopAbbreviation.trim().length == 0) {
            errorMessage = "请填写企业简称";
            $('#shopAbbreviationDiv').addClass("weui-cell_warn");
        } if ((objName=="s_addr"||objName=="objName")&&s_addr.trim().length == 0) {
            errorMessage = "请填写企业地址";
            $('#s_addrDiv').addClass("weui-cell_warn");
        }  if ((objName=="telephone"||objName=="objName")&&telephone.trim().length == 0) {
            errorMessage = "请填写客服电话";
            $('#telephoneDiv').addClass("weui-cell_warn");
        }else if((objName=="telephone"||objName=="objName") && !(/^0\d{2,3}-?\d{7,8}$/.test(telephone)) ){  //客服电话验证
        	errorMessage = "客服电话格式不正确";
        	$('#telephoneDiv').addClass("weui-cell_warn");
        }
        if ((objName=="username"||objName=="objName")&&username.trim().length == 0) {
            errorMessage = "请填写联系人姓名";
            $('#usernameDiv').addClass("weui-cell_warn");
        }  if ((objName=="mobile"||objName=="objName") && mobile.trim().length != 11) {
            errorMessage = "请填写联系人电话";
            $('#mobileDiv').addClass("weui-cell_warn");
        }else if((objName=="mobile"||objName=="objName") && mobile.length == 11){
        	checkMobile(mobile);
        }	  
        if ((objName=="email"||objName=="objName")&&email.trim().length == 0) {
            errorMessage = "请填写联系人邮箱";
            $('#emailDiv').addClass("weui-cell_warn");
        }else if((objName=="email"||objName=="objName") && !(/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)) ){
        	errorMessage = "邮箱格式不正确";
        	$('#emailDiv').addClass("weui-cell_warn");
        }
        
        
        
        
        if (errorMessage != "") {
            $('#loadingToast').fadeOut(100);
            $("#DialogMessage").html("您有没填完的信息，请填写");
            $iosDialog2.fadeIn(200);
            return true;
        }
        return false;
    }

    ///商户入驻 第一步 数据保存
    function onclkAppCompany() {
    	window.location.href="https://www.iknowtec.net/auth/aliPay";
        /* $('#loadingToast').fadeIn(100);
        if (valdateAppCompany("objName")) {
            return;
        } else {
            $("#submitCompany").submit();
        } */
    }
</script>
</body>
